//
//  SmallDecisionsSlResultViewController.m
//  SmallDecisions
//
//  Created by 李付雄 on 2025/8/6.
//

#import "SmallDecisionsSlResultViewController.h"

@interface SmallDecisionsSlResultViewController ()

@property(nonatomic,strong) UIView *containerView;
@property(nonatomic,strong) UILabel *titleLabel;
@property(nonatomic,strong) UILabel *contentLabel;
@property(nonatomic,strong) UIImageView *stateImageView;
@property(nonatomic,strong) UIButton *sureBtn;
@end

@implementation SmallDecisionsSlResultViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    [self containerView];
    [self titleLabel];
    [self contentLabel];
    [self stateImageView];
    [self sureBtn];
}

- (UIView *)containerView {
    if(!_containerView) {
        _containerView = [[UIView alloc] init];
        _containerView.backgroundColor = SmallDecisionsPurpleColor;
        _containerView.layer.cornerRadius = 10;
        _containerView.layer.masksToBounds = YES;
        [self.view addSubview:_containerView];
        [_containerView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(30);
            make.right.mas_equalTo(-30);
            make.centerY.mas_equalTo(-40);
        }];
    }
    return _containerView;
}

- (UILabel *)titleLabel {
    if(!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor = SmallDecisionsThemeColor;
        _titleLabel.font = SmallDecisionsSetBoldFontSize(28);
        _titleLabel.text = @"扫雷爆炸";
        _titleLabel.textAlignment = 1;
        [self.containerView addSubview:_titleLabel];
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_offset(20);
            make.left.mas_equalTo(20);
            make.right.mas_equalTo(-20);
        }];
    }
    return _titleLabel;
}


- (UILabel *)contentLabel {
    if(!_contentLabel) {
        _contentLabel = [[UILabel alloc] init];
        _contentLabel.textColor = SmallDecisionsThemeFontColor;
        _contentLabel.font = SmallDecisionsSetBoldFontSize(16);
        _contentLabel.text = @"好运气来了，挡也挡不住!";
        _contentLabel.textAlignment = 1;
        [self.containerView addSubview:_contentLabel];
        [_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.titleLabel.mas_bottom).offset(20);
            make.left.right.equalTo(self.titleLabel);
        }];
    }
    return _contentLabel;
}

- (UIImageView *)stateImageView {
    if(!_stateImageView) {
        _stateImageView = [[UIImageView alloc] init];
        _stateImageView.image = [UIImage imageNamed:@"sl_bomb_img"];
        _stateImageView.contentMode = UIViewContentModeScaleAspectFit;
        [self.containerView addSubview:_stateImageView];
        [_stateImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentLabel.mas_bottom).offset(30);
            make.centerX.mas_offset(0);
            make.height.width.mas_offset(100);
            make.bottom.mas_offset(-40);
        }];
    }
    return _stateImageView;
}

- (UIButton *)sureBtn {
    if(!_sureBtn) {
        _sureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        if(self.allEnd) {
            [_sureBtn setTitle:@"继续" forState:UIControlStateNormal];
        } else {
            [_sureBtn setTitle:@"再战一局" forState:UIControlStateNormal];
        }
        [_sureBtn setTitleColor:SmallDecisionsThemeFontColor forState:UIControlStateNormal];
        [_sureBtn setTitleColor:[UIColor clearColor] forState:UIControlStateHighlighted];
        _sureBtn.titleLabel.font = SmallDecisionsSetBoldFontSize(14);
        _sureBtn.layer.cornerRadius = 30;
        _sureBtn.layer.masksToBounds = YES;
        _sureBtn.backgroundColor = SmallDecisionsThemeColor;
        [_sureBtn addTarget:self action:@selector(sureBtnAction) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:_sureBtn];
        [_sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(60);
            make.left.equalTo(self.containerView).offset(20);
            make.right.equalTo(self.containerView).offset(-20);
            make.top.equalTo(self.containerView.mas_bottom).offset(40);
        }];
    }
    return _sureBtn;
}

- (void)sureBtnAction {
    if(self.callback) {
        self.callback(@{@"refresh":@(!self.allEnd)});
    }
    [SmallDecisionsNavigatorManager dismissViewControllerAnimated:YES completion:nil];
}
@end
